package edu.ujf.sharepas.impl;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.util.Properties;
import java.util.logging.Logger;


public class Constante {
	
	
	  public static final String[] VIDEO_FILTER_NAMES = {
	      "AVI Files (*.avi)",
	      "Matroska Video Files (*.mkv)",
	      "MPG Video Files (*.mpg)",
	      "MPEG Video Files  Files (*.mpeg)",
	      "MP4 Files (*.mp4)" };

	 
	  public static final String[] VIDEO_FILTER_EXTS = { "*.avi", "*.mkv", "*.mpg", "*.mpeg", "*.mp4"};
	  
	  public static final String[] PHOTO_FILTER_NAMES = {
	      "JPG Files (*.jpg)",
	      "JPEG Files (*.jpeg)",
	      "Bitmap Files (*.bmp)",
	      "PNG Files (*.png)"};

	 
	  public static final String[] PHOTO_FILTER_EXTS = { "*.jpg", "*.jpeg", "*.bmp", "*.png"};
	  
	  public static final String[] AUDIO_FILTER_NAMES = {
	      "MP3 Files (*.mp3)",
	      "Windows Media Audio Files (*.wma)",
	      "Ogg Vorbis Files (*.ogg)",
	      "Waveform Audio Format Files (*.wav)",
	      "Free Lossless Audio Codec Files (*.flac)" };
	    

	 
	  public static final String[] AUDIO_FILTER_EXTS = { "*.mp3", "*.ogg", "*.wav", "*.flac",".wma"};
	
	  public static final String[] DOC_FILTER_NAMES = {
	      "Zip Archive Files (*.zip)",
	      "Microsoft Word Files (*.doc)",
	      "Microsoft PowerPoint Files (*.ppt)",
	      "Portable Document Files (*.pdf)",
	      "OpenOffice.org Spreadsheet Files (*.sxc)",
	      "Microsoft Excel Spreadsheet Files (*.xls)",
	      "Comma Separated Values Files (*.csv)", "All Files (*.*)"};

	 
	  public static final String[] DOC_FILTER_EXTS = {"*.zip","*.pdf","*.ppt","*.doc", "*.sxc", "*.xls", "*.csv", "*.*"};
	  
	
	public static enum Property{
		DEFAULT_USER("User"),SERV_NAME("SERV_NAME"),SERVER_ADDR("SERV_ADDR"),ID("Id"),USERLIB("UserLibrary"), FRIEND_PATH("Friends"), AVATAR("Avatar"),MESSAGE("Message");
		
		private String name;
		
		private Property(String name){
			this.name = name;
		}
		
		public String toString(){
			return this.name;
		}
	}
	
	public static enum CategoryType{

		VIDEO("Video"), PHOTO("Photo"), AUDIO("Audio"), DOC("doc");
		
		private String name;
		
		private int type;
		private CategoryType(String name){
			this.name = name;
			if( name.equalsIgnoreCase("Video") ){
				this.type = 0;
			}else if( name.equalsIgnoreCase("Photo") ){
				this.type = 1;
			}else if( name.equalsIgnoreCase("Audio") ){
				this.type = 2;
			}else if( name.equalsIgnoreCase("doc") ){
				this.type = 3;
			}
		}
		
		public String toString(){
			return name;
		}
		
		public int toInt(){
			return type;
		}
	}
	
	public static enum Right{
		READ("read"), WRITE("write");
		
		private String name;
		
		private int type;
		
		private Right(String name){
			this.name = name;
			if( name.equalsIgnoreCase("read") ){
				this.type = 1;
			}else if( name.equalsIgnoreCase("write") ){
				this.type = 2;
			}
		}
		
		public String toString(){
			return this.name;
		}
		
		public int toInt(){
			return type;
		}
	}
	 public static enum UserState{
	        CONNECTED("connected"),DISCONNECTED("disconnected"), BUSY("busy");

	        private String name ;

	        private UserState(String name){
	            this.name = name;
	        }
	        public String toString(){
	            return this.name;
	        }
	    }
	
	private static Properties property = null;
	
	private static String propertyFile = "sharepas.properties";	
	private static Logger sharePasLog = null;
	
	public static String getSharePasProperty(String propertyName){
		if( property != null ){
			// initialisation
			return property.getProperty(propertyName);
		}else{
			property = new Properties();
			try{
				File f = new File(propertyFile);
				File conf = new File("config");
				if ( !conf.isDirectory() ){
					conf.mkdir();
				}
				File fr = new File("config/friends");
				if ( !fr.isDirectory() ){
					fr.mkdir();
				}
				if( !f.exists() ){
					f.createNewFile();
					BufferedWriter fw = new BufferedWriter(new FileWriter(f));
					fw.write("Id=1\n");
					fw.write("User=default\n");
					fw.write("Message=default\n");
					fw.write("Avatar=default.png\n");
					fw.write("UserLibrary=config/user.lib\n");
					fw.write("Friends=config/friends/\n");
					fw.write("SERV_ADDR=localhost\n");
					fw.write("SERV_NAME=ServMessage\n");
					fw.close();
				}
				property.load(new FileReader(propertyFile));
			}catch(Exception e){
				e.printStackTrace();
			}
			return property.getProperty(propertyName);
		}
	}
	
	public static Logger getSharePasLog(){
		if( sharePasLog != null ){
			return sharePasLog;
		}else{
			sharePasLog = Logger.getLogger("sharePas.log");
			return sharePasLog;
		}
	}
	
}
